include_directories(${CMAKE_CURRENT_LIST_DIR}/source/grad)
include_directories(${CMAKE_CURRENT_LIST_DIR}/source/optimizer)
include_directories(${CMAKE_CURRENT_LIST_DIR}/source/parameters)
include_directories(${CMAKE_CURRENT_LIST_DIR}/source/module)
include_directories(${CMAKE_CURRENT_LIST_DIR}/source/transformer)
include_directories(${CMAKE_CURRENT_LIST_DIR}/source/data)
include_directories(${CMAKE_CURRENT_LIST_DIR}/source/models)
include_directories(${CMAKE_CURRENT_LIST_DIR}/source/datasets)
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../../)
file(GLOB GRAD ${CMAKE_CURRENT_LIST_DIR}/source/grad/*)
file(GLOB TRANSFORMER ${CMAKE_CURRENT_LIST_DIR}/source/transformer/*)
file(GLOB MODULES ${CMAKE_CURRENT_LIST_DIR}/source/module/*)
file(GLOB PARAMETER ${CMAKE_CURRENT_LIST_DIR}/source/parameters/*)
file(GLOB OPTIMIZER ${CMAKE_CURRENT_LIST_DIR}/source/optimizer/*)
file(GLOB DATALOADER ${CMAKE_CURRENT_LIST_DIR}/source/data/*)
file(GLOB MODELS ${CMAKE_CURRENT_LIST_DIR}/source/models/*)
file(GLOB DATASETS ${CMAKE_CURRENT_LIST_DIR}/source/datasets/*)

IF(MNN_BUILD_SHARED_LIBS)
    set(MNN_LIBARY_TYPE SHARED)
ELSE()
    set(MNN_LIBARY_TYPE STATIC)
ENDIF()
option(MNN_BUILD_TRAIN_MINI "Don't build dataset and models" OFF)
if (MNN_BUILD_TRAIN_MINI)
    add_library(MNNTrain ${MNN_LIBARY_TYPE} ${GRAD} ${BASIC_INCLUDE} ${PARAMETER} ${OPTIMIZER} ${MODULES} ${DATALOADER} ${TRANSFORMER})
else()
    add_library(MNNTrain ${MNN_LIBARY_TYPE} ${GRAD} ${BASIC_INCLUDE} ${PARAMETER} ${OPTIMIZER} ${MODULES} ${DATALOADER} ${TRANSFORMER} ${MODELS} ${DATASETS})
endif()
target_link_libraries(MNNTrain ${MNN_DEPS})

add_executable(transformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/transformerExecution.cpp)
target_link_libraries(transformer.out MNNTrain)

add_executable(train.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/train.cpp ${SCHEMA} ${BASIC_INCLUDE})
target_link_libraries(train.out MNN)


add_executable(rawDataTransform.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/rawDataTransform.cpp ${SCHEMA} ${BASIC_INCLUDE})

include_directories(../../3rd_party/imageHelper/)
add_executable(dataTransformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/dataTransformer.cpp ${SCHEMA} ${BASIC_INCLUDE})
target_link_libraries(dataTransformer.out MNN)

option(MNN_USE_OPENCV "Use opencv" OFF)

file(GLOB DEMOSOURCE ${CMAKE_CURRENT_LIST_DIR}/source/demo/*)
if (MNN_BUILD_TRAIN_MINI)
    add_executable(runTrainDemo.out ${DEMOSOURCE} ${BASIC_INCLUDE} ${DATASETS} ${MODELS})
else()
    add_executable(runTrainDemo.out ${DEMOSOURCE} ${BASIC_INCLUDE})
endif()
target_link_libraries(runTrainDemo.out MNNTrain)
if (MNN_USE_OPENCV)
    set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_ORIGIN})
    set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_ORIGIN})
    find_package(OpenCV REQUIRED)
    include_directories(${OpenCV_INCLUDE_DIRS})
    add_definitions(-D MNN_USE_OPENCV)
    target_link_libraries(runTrainDemo.out ${OpenCV_LIBS})
endif()
